using System.Windows.Forms;
using Mbs.Globalization;
using Mbs.Modularity.AddIns;
using Mbs.Elements;
using Mbs.ComponentModel.Container;

namespace Mbs.Windows.Elements.Builders
{
    [Component(Id = "ToolStrip.Status.Label", Service = typeof(IElementBuilder))]
    public class ToolStripStatusLabelBuilder : ToolStripLabelBuilder
    {
        protected override ToolStripLabel CreateItem(IAddInItem addInItem)
        {
            return new MbsToolStripStatusLabel(addInItem);
        }

        private class MbsToolStripStatusLabel : ToolStripStatusLabel, Mbs.Globalization.ISupportGlobalization, IAddInItemHost
        {
            public IAddInItem AddInItem { get; private set; }
            public MbsToolStripStatusLabel(IAddInItem addInItem)
            {
                AddInItem = addInItem;
                IsSupportGlobalization = true;

                this.Initialize(addInItem);
                InitializeResource();

            }

            public bool IsSupportGlobalization { get; set; }

            public void InitializeResource()
            {
                Text = StringParser.Parse(AddInItem.Label);
                Image = AddInItem.Properties.Contains("Icon") ? ResourceRepository.Images.Get(AddInItem.Properties.Get<string>("Icon")) : null;
                if (AddInItem.Properties.Contains("ToolTip"))
                    ToolTipText = StringParser.Parse(AddInItem.Properties.Get<string>("ToolTip"));
            }

            public void RefreshResource()
            {
                InitializeResource();
            }
        }
    }
}
